package com.zs.games.utils;


import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author: LiChao
 * @dateTime: 2019/7/4 17:56
 * @description: Md5帮助类
 **/
public final class Md5Util {

    public static String md5Hex(String data) {
        try {
            StringBuffer sb = new StringBuffer();
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(data.getBytes(Charset.defaultCharset()));
            byte b[] = digest.digest();
            int i;
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0){
                    i += 256;
                }
                if (i < 16){
                    sb.append("0");
                }
                sb.append(Integer.toHexString(i));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }




}